<template>
  <div>
    <div class="content">
        <div class="content1-top"><p>{{datename}}</p></div>
        <div class="content1-footer">
            <div>
                <div>
                    <span>认领总额度</span>
                </div>
                <div>
                    {{topData[0]}}
                </div>
            </div>
            <div>
                <div>
                    <span>剩余额度</span>
                </div>
                <div>
                    {{topData[1]}}
                </div>
            </div>
            <div>
                <div>
                    <span>当前企业基线</span>
                </div>
                <div>
                    {{topData[2]}}
                </div>
            </div>
        </div>
    </div>
    <div class="content">
        <div class="content2-top">
            <div>安排表</div>
            <div>
                <el-button size="small">提交</el-button>
                <i class="el-icon-download"></i>
            </div>
        </div>
        <div class="content2-footer">
            <div v-for="item in surplusItem" :key="item.index">
                <div>{{item.name}}(剩余额度：<span style="color:red">{{item.surplus}}</span>)</div>
                <div>
                    <el-input id="el-input-table"
                  size="mini"
                  placeholder="输入额度"
                  type="number"
                  v-model="item.inputSurplus"
                  @change="handInput(item)">
                </el-input>
                <el-select v-model="item.selectSurplus"
                filterable placeholder="请选择" 
                id="el-select-table" allow-create 
                 size="mini" @change="handSelect(item)">
                  <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
                </div>
            </div>
        </div>
    </div>
    <div class="content">
        <div class="content3-top">
            <div>特殊情况</div>
        </div>
        <div>
            <el-form ref="form" :model="form" label-width="80px" :rules="rules">
                <el-form-item label="企业名称" prop="busName">
                    <el-select v-model="form.bussName"  placeholder="请选择企业名称">
                        <el-option
                            v-for="item in bussOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="姓名" prop="name">
                    <el-input class="inputel" v-model="form.name"></el-input>
                </el-form-item>
                <el-form-item label="电话" prop="phone">
                    <el-input class="inputel" v-model="form.phone" type="number"></el-input>
                </el-form-item>
                <el-form-item label="特俗情况" prop="desc">
                    <el-input class="inputel" type="textarea" v-model="form.desc"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary">提交</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
  </div>
</template>

<script>
export default {
    data() {
        return {
            form:{
                bussName:'',
                name:'',
                phone:'',
                desc:''
            },
            rules:{
                name:[
                    { required: true, message: '请输入姓名', trigger: 'blur' },
                    { min: 2, max: 7, message: '请输入正确格式', trigger: 'blur' }
                ],
                bussName: [
                    { required: true, message: '请选择企业', trigger: 'blur' }
                ],
                phone:[
                    { required: true, message: '请输入手机号', trigger: 'blur' },
                    { min: 11, max: 11,  message: '请输入正确手机号', trigger: 'blur' }
                ],
                desc:[
                    {required: true, message: '请输入情况描述', trigger: 'blur' }
                ]
            },
            bussOptions:[{
                value:"企业1",
                label:"企业1"
            },
            {
                value:"企业2",
                label:"企业2"
            }],
            options: [{
                value: '5%',
                label: '5%'
                }, {
                value: '10%',
                label: '10%'
                }, {
                value: '15%',
                label: '15%'
            }],
            datename: "2022年09月10日-2022年09月16日",
            topData:[2000,2000,555],
            surplusItem:[
                {
                    index:0,
                    name:"周一",
                    surplus:1200,
                    amount:1200,
                    inputSurplus:'',
                    selectSurplus:''
                },
                {
                    index:1,
                    name:"周二",
                    surplus:800,
                    amount:800,
                    inputSurplus:'',
                    selectSurplus:''
                },
                {
                    index:2,
                    name:"周三",
                    surplus:1200,
                    amount:1200,
                    inputSurplus:'',
                    selectSurplus:''
                },
                {
                    index:3,
                    name:"周四",
                    surplus:200,
                    amount:200,
                    inputSurplus:'',
                    selectSurplus:''
                },
                {
                    index:4,
                    name:"周五",
                    surplus:200,
                    amount:200,
                    inputSurplus:'',
                    selectSurplus:''
                },
                {
                    index:5,
                    name:"周六",
                    surplus:200,
                    amount:200,
                    inputSurplus:'',
                    selectSurplus:''
                },
                {
                    index:6,
                    name:"周日",
                    surplus:200,
                    amount:200,
                    inputSurplus:'',
                    selectSurplus:''
                }
            ]
        }
    },
    methods: {
        //安排表的输入框
        handInput(item) {
            //当为空时，返回并且百分比设置为空
            if(item.inputSurplus == ''){
                item.selectSurplus = ''
                console.log(this.surplusItem)
                return
            }
            //计算剩余额度
            this.surplusItem[item.index].surplus = 
            this.surplusItem[item.index].amount - parseInt(item.inputSurplus);
            //计算百分比
            item.selectSurplus = (parseInt(item.inputSurplus)*100/this.topData[2]).toFixed(0) + '%'

        },
        //安排表的选择框
        handSelect(item){
            //当选择器为空，输入框也为空
            if(item.selectSurplus == ''){
                item.inputSurplus = ''
                return
            }
            //计算输入值
            if(item.selectSurplus[item.selectSurplus.length-1]!= '%'){return}
            let per = parseInt(item.selectSurplus.split('%'))
            item.inputSurplus = per*this.topData[2]/100
            this.surplusItem[item.index].surplus = 
            this.surplusItem[item.index].amount - parseInt(item.inputSurplus);
        }
    },
}
</script>

<style scoped>
.content1-top{
    width: 100%;
    height: 60px;
    text-align: center;
    line-height: 60px;
    font-size: 30px;
    font-weight: 500;
}
.content1-footer{
    margin-top: 20px;
    margin-top: 30px;
    width: 100%;
    height: 100px;
    text-align: center;
    display: flex;
    justify-content: space-around;
    margin-bottom: 30px;
}
.content1-footer>div{
    width: 200px;
    height: 100px;
    border: 1px solid #EBEEF5;
    border-radius: 4px;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
.content1-footer>div>div:first-child{
    height: 40px;
    width: 200px;
    line-height: 40px;
    font-weight: 600;
    font-size: large;
}
.content1-footer>div>div:last-child{
    height: 40px;
    width: 200px;
    line-height: 40px;
    font-weight: 400;
    font-size: large;
}
.content{
    border:1px solid #EBEEF5;
    border-radius: 2px;
    margin-bottom: 10px;
}
.content2-top{
    width: 100%;
    height: 40px;
    display: flex;
}
.content2-top>div{
    width: 50%;
    height: 40px;
    line-height: 40px;
}
.content2-top>div:first-child{
    text-align: left;
    padding-left: 10px;
}
.content2-top>div:last-child{
    text-align: right;
    padding-right: 10px;
    font-size: larger;
}
/deep/.el-button{
    margin-right: 10px;
}
.content2-footer{
    height: 200px;
}
.content2-footer>div{
    width: 25%;
    height: 100px;
    float: left;
    text-align: center;
    line-height: 50px;
}
.content2-footer>div>div:first-child{
    height: 50px;
    background-color: #EBEEF5;
}
.content2-footer>div>div:last-child{
    height: 50px;
    display: flex;   
}
/deep/#el-input-table::-webkit-input-placeholder{
    font-size: 0.1px; 
}
/deep/#el-input-table{
    
    width: 60%;
}
/deep/#el-select-table{
    
    width: 100%;
}
/deep/input::-webkit-outer-spin-button,
/deep/input::-webkit-inner-spin-button {
  -webkit-appearance: none !important;
}
.content3-top{
    width: 100%;
    height: 40px;
    padding-left: 10px;
    line-height: 40px;
}
/deep/.inputel{
    width: 230px;
}
</style>